# -*- coding: UTF-8 -*- #
"""
-------真正的勇士， 敢于直面惨淡的Warning、 敢于正视淋漓的Error-----
@author : 贾鹏博
@file : util_excel.py
@time : 2022/5/10 9:17
"""

# 第三方库
import openpyxl


def get_excel():
    # 获取工作薄
    book = openpyxl.load_workbook('../test_data/params.xlsx')
    # 获取工作表sheet1
    sheet = book.active
    # 读取数据  结果为：((<Cell 'Sheet1'.A1>, <Cell 'Sheet1'.B1>, <Cell 'Sheet1'.C1>), (<Cell 'Sheet1'.A2>, <Cell 'Sheet1'.B2>, <Cell 'Sheet1'.C2>), (<Cell 'Sheet1'.A3>, <Cell 'Sheet1'.B3>, <Cell 'Sheet1'.C3>))
    cells = sheet['A1:C3']
    print(cells)
    values = []
    # 结果：(<Cell 'Sheet1'.A1>, <Cell 'Sheet1'.B1>, <Cell 'Sheet1'.C1>)   (<Cell 'Sheet1'.A2>, <Cell 'Sheet1'.B2>, <Cell 'Sheet1'.C2>)    (<Cell 'Sheet1'.A3>, <Cell 'Sheet1'.B3>, <Cell 'Sheet1'.C3>)
    for row in cells:
        data = []
    # 结果为：(<Cell 'Sheet1'.A1> ......
        for cell in row:
            data.append(cell.value)  # [1 1 2], [3,6,9], [100,200,300]
        values.append(data)  # [[1 1 2], [3,6,9], [100,200,300]]
    print(values) # [[1 1 2], [3,6,9], [100,200,300]]
    return values